package com.liveinstars.activity.business.activity.repository.persistence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liveinstars.activity.business.activity.repository.po.ActivityMembers;
import com.liveinstars.activity.business.activity.repository.mapper.ActivityMembersMapper;
import com.liveinstars.activity.business.activity.repository.facade.IActivityMembersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ting
 * @since 2020-08-24
 */
@Service
public class ActivityMembersServiceImpl extends ServiceImpl<ActivityMembersMapper, ActivityMembers> implements IActivityMembersService {

    @Override
    public List<ActivityMembers> listByUserId(Integer userId, int i) {
        QueryWrapper<ActivityMembers> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        return this.list(wrapper);
    }

    @Override
    public List<ActivityMembers> listByActivityId(Integer id) {
        QueryWrapper<ActivityMembers> wrapper = new QueryWrapper<>();
        wrapper.eq("activity_id", id);
        return this.list(wrapper);
    }

    @Override
    public int countByActivityId(Integer activityId) {
        QueryWrapper<ActivityMembers> wrapper = new QueryWrapper<>();
        wrapper.eq("activity_id", activityId);
        return this.count(wrapper);
    }

    @Override
    public ActivityMembers getActivityMemberByActivityIdAndUserId(Integer activityId, Integer userId) {
        QueryWrapper<ActivityMembers> wrapper = new QueryWrapper<>();
        wrapper.eq("activity_id", activityId);
        wrapper.eq("user_id", userId);
        return this.getOne(wrapper, false);
    }

    @Override
    public boolean addMember(ActivityMembers members) {
        return this.save(members);
    }
}
